<?php
class Core_Business_Trainingession extends Core_Business_Abstract{
	private $_id;
	private $_trainingid;
	private $_trainerid;
	private $_startdate;
	private $_enddate;
	private $_seatavailable;
	private $_created;
	private $_updated;
	
	public function getId() {return $this->_id;}
	public function setId($value) {
		if($value)
			$this->_id = $value;
		else
			throw new Exception("Property value for object ".__CLASS__.", property ".__METHOD__);
	}
	/***
	 * return the training instance associated with this session
	 * @return Core_Business_Training|null
	 */
	public function getTraining() {
		return Core_Business_Training::getById($this->_trainingid);
	}
	
	public function getTrainingid() {
		return $this->_trainingid;
	}
	public function setTrainingid($value) {
		if ($value)
			$this->_trainingid = $value;
		else 
			throw new Exception("Property value for object ".__CLASS__.", property ".__METHOD__);
	}
	public function getTrainerid() {return $this->_trainerid;}
	public function setTrainerid($value) {
		if(is_int($value))
			$this->_trainerid = $value;
		else
			throw new Exception("Property value for object ".__CLASS__.", property ".__METHOD__);
	}
	
	public function getStartdate() {return $this->_startdate;}
	public function setStartdate($value) {
		$this->_startdate = $value;
	}
	
	public function getEnddate() {return $this->_enddate;}
	public function setEnddate($value) {
		$this->_enddate = $value;
	}
	
	public function getSeatavailable() {return $this->_seatavailable;}
	public function setSeatavailable($value) {
		if($value)
			$this->_seatavailable = $value;
		else 
			throw new Exception("Property value for object ".__CLASS__.", property ".__METHOD__);
	}
	
	public function getCreated() {return $this->_created;}
	public function setCreated($value) {}
	public function getUpdated() {return $this->_updated;}
	public function setUpdated($value) {}
	
	public function save() {
		$map = new Core_Business_Trainingession();
		$map->save($this);
	}
	
	public static function getSessionByTrainingId($trainingid) {
		$map = new Core_Data_Mappers_Trainingsession();
		$rows = $map->getDbTable()->fetchAll(array('trainingid = ?'=>$trainingid));
		$sessionCollection = array();
		if(isset($rows) && count($rows)>0) {
			foreach ($rows as $item) {
				$sessionCollection[] = $this->map($item);
			}
		}
		return $sessionCollection;
	}
}
?>